Update source when getting its root_package
authorCarol (Nichols || Goulding) <carol.nichols@gmail.com>
Sat, 19 Sep 2015 17:06:23 +0000 (13:06 -0400)
committerCarol (Nichols || Goulding) <carol.nichols@gmail.com>
Sun, 20 Sep 2015 03:19:16 +0000 (23:19 -0400)
This way, callers who want source.root_package() don't have to remember
to call source.update() before that. Since source.update() is a noop if
the source has already been updated, there's not a reason I could see to
raise an error instead of just calling it.

The one remaining place that calls source.root_package() that is still
calling source.update() immediately before is in bin/read_manifest,
where the errors from update() are mapped to CliErrors.

src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_doc.rs
src/cargo/ops/cargo_fetch.rs
src/cargo/ops/cargo_generate_lockfile.rs
src/cargo/ops/cargo_package.rs
src/cargo/ops/cargo_pkgid.rs
src/cargo/ops/cargo_run.rs
src/cargo/ops/registry.rs
src/cargo/sources/path.rs

index 03b0575556dbad9c65ec102384ba85f9ecc61a28..caae5e4f9c73a3d7023feecb78e95f63cae0fcc4 100644 (file)
@@ -19,7 +19,6 @@ pub struct CleanOptions<'a> {
 pub fn clean(manifest_path: &Path, opts: &CleanOptions) -> CargoResult<()> {
     let mut src = try!(PathSource::for_path(manifest_path.parent().unwrap(),
                                             opts.config));
-    try!(src.update());
     let root = try!(src.root_package());
     let target_dir = opts.config.target_dir(&root);
 
index 74d0b09423efd4bd70433788ff7b9ff468bea2fa..f177e5e7e4e3496b9c83f4745b3cda6a0ab1a217 100644 (file)
@@ -89,8 +89,6 @@ pub fn compile<'a>(manifest_path: &Path,
 
     let mut source = try!(PathSource::for_path(manifest_path.parent().unwrap(),
                                                options.config));
-    try!(source.update());
-
     // TODO: Move this into PathSource
     let package = try!(source.root_package());
     debug!("loaded package; package={}", package);
index 8090a35fe18b72b0724186156e390ae6a4cac757..763512caffcd2f7910d891df8c350f106896e806 100644 (file)
@@ -4,7 +4,6 @@ use std::path::Path;
 use std::process::Command;
 
 use core::PackageIdSpec;
-use core::source::Source;
 use ops;
 use sources::PathSource;
 use util::{CargoResult, human};
@@ -18,7 +17,6 @@ pub fn doc(manifest_path: &Path,
            options: &DocOptions) -> CargoResult<()> {
     let mut source = try!(PathSource::for_path(manifest_path.parent().unwrap(),
                                                options.compile_opts.config));
-    try!(source.update());
     let package = try!(source.root_package());
 
     let mut lib_names = HashSet::new();
index cbd3382f90da99f780d61dd8ad622dc777aa1e16..34e6bb27d74dda7f77dd2b42574a67da9c683633 100644 (file)
@@ -10,7 +10,6 @@ use util::{CargoResult, Config, human, ChainError};
 pub fn fetch(manifest_path: &Path, config: &Config) -> CargoResult<()> {
     let mut source = try!(PathSource::for_path(manifest_path.parent().unwrap(),
                                                config));
-    try!(source.update());
     let package = try!(source.root_package());
 
     let mut registry = PackageRegistry::new(config);
index f561664b876f9e62fb5737884f0f2dd76a921b64..c3de1dc435b8dd66d3ff6073d06c9c2b1c54c830 100644 (file)
@@ -3,7 +3,7 @@ use std::path::Path;
 
 use core::PackageId;
 use core::registry::PackageRegistry;
-use core::{Source, Resolve, SourceId};
+use core::{Resolve, SourceId};
 use core::resolver::Method;
 use ops;
 use sources::{PathSource};
@@ -21,7 +21,6 @@ pub fn generate_lockfile(manifest_path: &Path, config: &Config)
                          -> CargoResult<()> {
     let mut source = try!(PathSource::for_path(manifest_path.parent().unwrap(),
                                                config));
-    try!(source.update());
     let package = try!(source.root_package());
     let mut registry = PackageRegistry::new(config);
     registry.preload(package.package_id().source_id(), Box::new(source));
@@ -36,7 +35,6 @@ pub fn update_lockfile(manifest_path: &Path,
                        opts: &UpdateOptions) -> CargoResult<()> {
     let mut source = try!(PathSource::for_path(manifest_path.parent().unwrap(),
                                                opts.config));
-    try!(source.update());
     let package = try!(source.root_package());
 
     let previous_resolve = match try!(ops::load_pkg_lockfile(&package)) {
index bcd74f460a7accf17c9312ce1113f34a00d5fcfe..684c539fe04f98192a2a31f49420217d3daf7c0b 100644 (file)
@@ -6,7 +6,7 @@ use tar::Archive;
 use flate2::{GzBuilder, Compression};
 use flate2::read::GzDecoder;
 
-use core::{Source, SourceId, Package, PackageId};
+use core::{SourceId, Package, PackageId};
 use sources::PathSource;
 use util::{self, CargoResult, human, internal, ChainError, Config};
 use ops;
@@ -29,7 +29,6 @@ pub fn package(manifest_path: &Path,
                metadata: bool) -> CargoResult<Option<PathBuf>> {
     let mut src = try!(PathSource::for_path(manifest_path.parent().unwrap(),
                                             config));
-    try!(src.update());
     let pkg = try!(src.root_package());
 
     if metadata {
index d900510b3803673b5cb99036ef66b5b142ae48f0..9e982aa37cf5a55621701fd178a7a9d8a2299ab6 100644 (file)
@@ -1,7 +1,7 @@
 use std::path::Path;
 
 use ops;
-use core::{Source, PackageIdSpec};
+use core::{PackageIdSpec};
 use sources::{PathSource};
 use util::{CargoResult, human, Config};
 
@@ -10,7 +10,6 @@ pub fn pkgid(manifest_path: &Path,
              config: &Config) -> CargoResult<PackageIdSpec> {
     let mut source = try!(PathSource::for_path(&manifest_path.parent().unwrap(),
                                                config));
-    try!(source.update());
     let package = try!(source.root_package());
 
     let lockfile = package.root().join("Cargo.lock");
index 419a7ab155a79ff9fd58a6ccde8c9cac091669e8..5db34762376f1655a917e879d3b17de2f4c875aa 100644 (file)
@@ -2,7 +2,6 @@ use std::path::Path;
 
 use ops::{self, ExecEngine, CompileFilter};
 use util::{self, CargoResult, human, process, ProcessError};
-use core::source::Source;
 use sources::PathSource;
 
 pub fn run(manifest_path: &Path,
@@ -11,7 +10,6 @@ pub fn run(manifest_path: &Path,
     let config = options.config;
     let mut src = try!(PathSource::for_path(&manifest_path.parent().unwrap(),
                                             config));
-    try!(src.update());
     let root = try!(src.root_package());
 
     let mut bins = root.manifest().targets().iter().filter(|a| {
index 9f9b035f8048db6cce72e6cf8c0d429606a6c295..a81dda28ce3385ce6ac440b868c75c8d2f786d8e 100644 (file)
@@ -33,7 +33,6 @@ pub fn publish(manifest_path: &Path,
                verify: bool) -> CargoResult<()> {
     let mut src = try!(PathSource::for_path(manifest_path.parent().unwrap(),
                                             config));
-    try!(src.update());
     let pkg = try!(src.root_package());
 
     let (mut registry, reg_id) = try!(registry(config, token, index));
@@ -266,7 +265,6 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> {
             let manifest_path = try!(find_root_manifest_for_cwd(None));
             let mut src = try!(PathSource::for_path(manifest_path.parent().unwrap(),
                                                     config));
-            try!(src.update());
             let pkg = try!(src.root_package());
             pkg.name().to_string()
         }
@@ -329,7 +327,6 @@ pub fn yank(config: &Config,
             let manifest_path = try!(find_root_manifest_for_cwd(None));
             let mut src = try!(PathSource::for_path(manifest_path.parent().unwrap(),
                                                     config));
-            try!(src.update());
             let pkg = try!(src.root_package());
             pkg.name().to_string()
         }
index 0bca3de26f58d667d4542d05335859646c60aac4..8589836d28820b118d91f4e254ac3a8d5806e0e1 100644 (file)
@@ -46,12 +46,10 @@ impl<'cfg> PathSource<'cfg> {
         }
     }
 
-    pub fn root_package(&self) -> CargoResult<Package> {
+    pub fn root_package(&mut self) -> CargoResult<Package> {
         trace!("root_package; source={:?}", self);
 
-        if !self.updated {
-            return Err(internal("source has not been updated"))
-        }
+        try!(self.update());
 
         match self.packages.iter().find(|p| p.root() == &*self.path) {
             Some(pkg) => Ok(pkg.clone()),